package com.chenxin.wms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chenxin.common.constant.WmsConstants;
import com.chenxin.wms.domain.SpuEntity;
import com.chenxin.wms.domain.vo.SpuVO;
import com.chenxin.wms.mapper.SpuMapper;
import com.chenxin.wms.service.ISpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 物料Service业务层处理
 *
 * @author gry
 * @date 2025-03-31
 */
@Service
public class SpuServiceImpl implements ISpuService {
    @Autowired
    private SpuMapper spuMapper;

    @Override
    public SpuVO selectSpuViewById(Long spuId) {
        return spuMapper.selectSpuViewById(spuId);
    }

    public SpuEntity selectSpuBySpuNo(String spuNo) {
        QueryWrapper<SpuEntity> spuQW = new QueryWrapper<>();
        spuQW.eq("spu_no", spuNo);
        return spuMapper.selectOne(spuQW);
    }

    /**
     * 查询物料列表
     *
     * @param spuVo 物料
     * @return 物料
     */
    @Override
    public List<SpuVO> selectSpuList(SpuVO spuVo) {
        return spuMapper.selectSpuViewList(spuVo);
    }

    @Override
    public int insertSpu(SpuEntity spuEntity) {
        return spuMapper.insert(spuEntity);
    }

    /**
     * 修改物料
     *
     * @param spuEntity 物料
     * @return 结果
     */
    @Override
    public int updateSpu(SpuEntity spuEntity) {
        if (spuEntity == null) {
            return 0;
        }
        return spuMapper.updateById(spuEntity);
    }

    /**
     * 批量删除物料
     *
     * @param spuIds 需要删除的物料主键
     * @return 结果
     */
    @Override
    public int deleteSpuBySpuIds(Long[] spuIds) {
        return 0;
    }

    @Override
    public boolean checkSpuNoUnique(SpuEntity spuEntity) {
        return WmsConstants.UNIQUE;
    }
}
